# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  
  def current_user?(user)
    return true if session[:user_id] == @user.id
    return false
  end
  
  def current_user
    user = User.find(session[:user_id])
  end
  
  def link_to_set_role_of_user(options)
    link_to_remote 'Set', :url => set_role_path(:id => options[:id], :role_id => options[:role_id]), :confirm => "Are you sure?"
  end
  
  def will_paginate_remote(paginator, options={})
    update = ''
    # = options.delete(:update)
    url = options.delete(:url)
    movie_id = options[:movie_id]
    str = will_paginate(paginator, options)
    if str != nil
      str.gsub(/href="(.*?)"/) do
        "href=\"#\" onclick=\"new Ajax.Request('" + (url ? url + $1.sub(/[^\?]*/, '') : $1) +
        "\&movie_id=#{movie_id}', {asynchronous:true, evalScripts:true, method:'get',}); return false;\""
      end
    end
  end

end
  
